import { createRouter, createWebHistory } from "vue-router";
import { routes } from "./routes";

export const router = createRouter({
    history: createWebHistory(),
    routes,
    scrollBehavior(to, from, savedPosition) {
        return { top: 0 }
        // return { top: document.documentElement.scrollHeight }
    }
})

router.beforeEach((to, from, next) => {
    if (to.path === '/about') {
        if (confirm('是否继续访问about页面？')) {
            next()
        } else {
            next(false)
        }
    } else {
        next()
    }
})

router.afterEach((to, from) => {
    if (to.meta.title) {
        document.title = to.meta.title
    }
})